## 地理编码
import requests,json
import pandas as pd
key='025f09933411b23de9c674584a6bbda9'

def geo(key,address,city=None,batch='false',sig=None,output='json',callback=None):
    ##获取的Api的地理编码信息
    url='https://restapi.amap.com/v3/geocode/geo?parameters'
    params={
    'key':key,
    'address':address,
    'city':city,
    'batch':batch,
    'sig':sig,
    'output':output,
    'callback':callback
    }
    response=requests.get(url,params=params)
    results=response.json()['geocodes'][0]['location']
    # return
    return results

address1='广东省广州市中山大学'
中大_location=geocode(key,address1,city=None,batch='false',sig=None,output='json',callback=None)
中大_location

## 逆地理编码
def regeo(key,location,poitype=None,radius='1000',extensions='base',batch='false',roadlevel=None,sig=None,
          output='json',callback=None,homeorcorp='0'):
    ##经纬度坐标
    url='https://restapi.amap.com/v3/geocode/regeo?parameters'
    params={
        'key':key,
        'location':location,
        'poitype':poitype,
        'radius':radius,
        'extensions':extensions,
        'batch':batch,
        'sig':sig,
        'output':output,
        'callback':callback,
        'homeorcorp':homeorcorp
    }
    response=requests.get(url,params)
    results=response.json()
    return results

location1="113.679287,23.632575"
ngeo(key,location1,poitype=None,radius='1000',extensions='base',batch='false',roadlevel=None,sig=None,output='json',callback=None,homeorcorp='0')

## 路径规划
def walking(key,origin,location,sig=None,output='json',callback=None):
    ##步行路径规划
    url='https://restapi.amap.com/v3/direction/walking?parameters'
    params={
        'key':key,
        'origin':origin,
        'destination':location,
        'sig':sig,
        'output':output,
        'callback':callback,     
    }
    response=requests.get(url,params)
    results=response.json()
    # return
    return results

origin='113.291103,23.092973'
location='113.679287,23.632575'
walking(key,origin,location,sig=None,output='json',callback=None)

df = pd.json_normalize(walking(key,'113.384300,22.934005','113.359984,22.932857')['route']['paths'][0]['steps'])
df

df['instruction']

## 行政区域查询
def district(key,keywords=None,subdistrict='1',page='1',offset='20',extensions='base',filter='',callback=None,output='json'):
    #行政区域查询
    url='https://restapi.amap.com/v3/config/district?parameters'
    params={
        'key':key,
        'keywords':keywords,
        'subdistrict':subdistrict,
        'extensions':extensions,
        'page':page,
        'offset':offset,
        'filter':filter,
        'callback':callback,
        'output':output     
    }
    response=requests.get(url,params)
    results=response.json()
    # return
    return results

keywords='广东'
subdistrict='1'
district(key,keywords,subdistrict='1',page='1',offset='20',extensions='base',filter='',callback=None,output='json')

a=district(key,keywords,subdistrict='1',page='1',offset='20',extensions='base',filter='',callback=None,output='json')['districts'][0]['districts']
import pandas as pd
pd.json_normalize(a)['name']

## 搜索POI
def poi(keywords,city='',extensions='',citylimit=''):
    #关键词搜索
    url='https://restapi.amap.com/v3/place/text?parameters'
    key='025f09933411b23de9c674584a6bbda9'
    params={
        'key':key,
        'keywords':keywords,
        'city':city,
        'extensions':extensions,
        'citylimit':citylimit
      
    }
    response=requests.get(url,params)
    results=response.json()
    # return
    return results

keywords='学校'
city='广州'
citylimit='true'
text(keywords,city,extensions,citylimit)

## IP定位
def ip(key,id):
    # ip定位
    url='https://restapi.amap.com/v3/ip?parameters'
    key='025f09933411b23de9c674584a6bbda9'
    params={
        'key':key,
        'id':id
      
    }
    response=requests.get(url,params)
    results=response.json()
    # return
    return results

id='10.53.16.115'
ip(key,id)

## 静态地图
def amap(key,location,zoom,size='400*400',scale='1',markers=None,labels=None,paths=None,traffic='0',sig=None):
    ##获取静态地图信息
    url='https://restapi.amap.com/v3/staticmap?parameters'
    params={
    'key':key,
    'location':location,
    'zoom':zoom,
    'scale':scale,
    'markers':markers,
    'labels':labels,
    'paths':paths,
    'traffic':traffic,
    'sig':sig
    }
    r=requests.get(url,params)
    data=r.url
    return data

location='113.291103,23.092973'
zoom='17'
amap(key,location,zoom,size='400*400',scale='1',markers=None,labels=None,paths=None,traffic=None,sig=None)

## 坐标转换
def convert(key,locations,coordays='',sig='',output=''):
    url='https://restapi.amap.com/v3/assistant/coordinate/convert?parameters'
    params={
        'key':key,
        "locations":locations,
        'coordays':coordays,
        'sig':sig,
        'output':output
    }
    response=requests.get(url,params)
    r=response.json()
    return r

locations='116.481499,39.990475|116.481499,39.990375'
convert(key,locations,coordays='',sig='',output='')

## 天气查询
def weather(key,city,extensions='base',output=''):
    url='https://restapi.amap.com/v3/weather/weatherInfo?parameters'
    params={
        'key':key,
       'city':city,
        'extensions':extensions,
        'output':output
    }
    response=requests.get(url,params)
    r=response.json()
    return r

city='440500'
weather(key,city,extensions='base',output='')

## 输入提示
def input(key,keywords,type=None,location=None,city=None,
          citylimit='false',datatype=None,sig=None,output='json',callback=None):
    # 输入提示
    url='https://restapi.amap.com/v3/assistant/inputtips?parameters'
    params={
        'key':key,
        'keywords':keywords,
        'type':type,
        'location':location,
        'city':city,
        'citylimit':citylimit,
        'datatype':datatype,
        'sig':sig,
        'output':output,
        'callback':callback
    }
    response=requests.get(url,params)
    r=response.json()
    return r

keywords='广州塔'
input(key,keywords,type=None,location=None,city=None,citylimit='false',datatype=None,sig=None,output='json',callback=None)

## 交通态势
def traffic(key,rectangle,level='5',extensions='base',sig=None,output='json',callback=None):
    url='https://restapi.amap.com/v3/traffic/status/rectangle?parameters'
    params={
        'key':key,
        'rectangle':rectangle,
        'level':level,
        'extensions':extensions,
        'sig':sig,
        'output':output,
        'callback':callback,
    }
    response=requests.get(url,params)
    r=response.json()
    return r

rectangle='116.351147,39.966309;116.357134,39.968727'
traffic(key,rectangle,level='5',extensions='base',sig=None,output='json',callback=None)